// 获取当前时间
function yearTime(e) {
  var a = new Date();
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  if (e == 'year') {
    return y + '-' + m + '-' + d;
  }
  if (e == 'time') {
    return h + ':' + mm + ':' + s;
  }
  if (e == 'yearTime') {
    return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
  }
  return y + '-' + m + '-' + d;
}

// 获取当前时间
function yearTimetwo(e) {
  var a = new Date(e);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;
  return y + '-' + m + '-' + d;
}

// 时间戳展示正常时间***
function goTime(val) {
  var timestamp4 = new Date(val);
  // 利用拼接正则等手段转化为yyyy-MM-dd hh:mm:ss 格式
  return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
}

function week() {
  var h = a.getDay() - 1;
  var we = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期七']
  return we[h]
}

function dangqianTime() {
  // 获取当前之前的时间
  var end = Date.now()
  var start = 1000 * 60 * 60 * 0
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
}

function appleTime() {
  // 获取24个小时之前的时间
  var end = Date.now()
  var start = 1000 * 60 * 60 * 24
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
}
//获取十二个小时之前的时间
function shierTime() {
  // 获取24个小时之前的时间
  var end = Date.now()
  var start = 1000 * 60 * 60 * 12
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
}
//获取六小时之前的时间
function liuTime() {
  var end = Date.now()
  var start = 1000 * 60 * 60 * 6
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
}
//获取一周之前的时间24*7
function yizhouTime() {
  var end = Date.now()
  var start = 1000 * 60 * 60 * 24 * 7
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;

  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;

  return y + '-' + m + '-' + d + '  ' + h + ':' + mm + ':' + s;
}
//获取一月之前的时间24*7
function yiyueTime() {
  var end = Date.now()
  var start = 1000 * 60 * 60 * 24 * 30
  var interval = end - start; //结束 - 开始 = 毫秒值
  var a = new Date(interval);
  var y = a.getFullYear();
  var m = a.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = a.getDate();
  d = d < 10 ? "0" + d : d;
  var h = a.getHours();
  h = h < 10 ? "0" + h : h;
  var mm = a.getMinutes();
  mm = mm < 10 ? "0" + mm : mm;
  var s = a.getSeconds();
  s = s < 10 ? "0" + s : s;
  return y + '-' + m + '-' + d + '  ' + h + ':' + mm + ':' + s;
}


module.exports = {
  dangqianTime: dangqianTime,
  yearTimetwo: yearTimetwo,
  yearTime: yearTime,
  week: week,
  appleTime: appleTime,
  shierTime: shierTime,
  liuTime: liuTime,
  yiyueTime: yiyueTime,
  yizhouTime: yizhouTime
}
